import re

text1 = '11/27/2012'
text2 = 'Nov 27, 2012'

#match() 总是从字符串开始去匹配
if re.match(r'\d+/\d+/\d+', text1):
    print('yes')
else:
    print('no')

#如果你想使用同一个模式去做多次匹配，你应该先将模式字符串预编译为模式对象
datepat = re.compile(r'\d+/\d+/\d+')
if datepat.match(text1):
    print('yes')
else:
    print('no')

text = 'Today is 11/27/2012. PyCon starts 3/13/2013.'
print(datepat.findall(text))

datepat = re.compile(r'(\d+)/(\d+)/(\d+)')
m = datepat.match(text1)
print(m.group(0))
print(m.group(1))
print(m.group(2))
print(m.group(3))
print(m.groups())

for month, day, year in datepat.findall(text):
    print('{}-{}-{}'.format(year, month, day))

for m in datepat.finditer(text):
    print(m.groups())
